﻿using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using System.Collections.Generic;
using System.Collections;
using Android.Util;
using StoveTop.Models;

namespace StoveTop
{
	[Activity (Label = "StoveTop", MainLauncher = true)] 
	public class MainActivity : Activity
	{
		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);

			StoveTopDBHelper db = new StoveTopDBHelper (this);
			List<Tag> cats = db.GetAllTags ();
			List<Vocab> techs = db.GetAllVocab ();
			List<Equipment> equips = db.GetAllEquipment ();
			Console.WriteLine ("CTE sizes are " + cats.Count.ToString () + " " + techs.Count.ToString () + " " + equips.Count.ToString ());
			string[] cat_names = new string[cats.Count];
			for (int i = 0; i < cats.Count; i++) {
				cat_names[i] =  (cats[i].GetName ());
				Log.Debug ("DEBUG", "cat_names[" + i.ToString () + "] = " + cat_names [i]);
			}
			string[] tech_names = new string[techs.Count];
			for (int i = 0; i < techs.Count; i++) {
				tech_names [i] = (techs [i].GetName ());
				Log.Debug ("DEBUG", "tech_names[" + i.ToString () + "] = " + tech_names [i]);
			}
			string[] equip_names = new string[equips.Count];
			for (int i = 0; i < equips.Count; i++) {
				equip_names [i] = (equips [i].GetName ());
				Log.Debug ("DEBUG", "equips_names[" + i.ToString () + "] = " + equip_names [i]);
			}
				
			// Set our view from the "main" layout resource
			SetContentView (Resource.Layout.Main);

			Button catButton = FindViewById<Button> (Resource.Id.catButton);
			catButton.Click += (sender, e) => {
				var catListScreen = new Intent (this, typeof(StoveTopListActivity));
				catListScreen.PutExtra ("list", cat_names);
				StartActivity (catListScreen);
			};
			Button techButton = FindViewById<Button> (Resource.Id.techButton);
			techButton.Click += (sender, e) => {
				var techListScreen = new Intent (this, typeof(StoveTopListActivity));
				techListScreen.PutExtra ("list", tech_names);
				StartActivity (techListScreen);
			};
			Button equipButton = FindViewById<Button> (Resource.Id.equipmentButton);
			equipButton.Click += (sender, e) => {
				var equipListScreen = new Intent (this, typeof(StoveTopListActivity));
				equipListScreen.PutExtra ("list", equip_names);
				StartActivity (equipListScreen);
			};

			Button recipeTest = FindViewById<Button> (Resource.Id.startButton);
			recipeTest.SetText ("View sample recipe", Button.BufferType.Normal);
			recipeTest.Click += (sender, e) => {
				var recipeScreen = new Intent(this, typeof(StoveTop.Screens.StoveTopRecipeScreen));
				recipeScreen.PutExtra("recipeId", 2);
				StartActivity(recipeScreen);
			};

			Button timerTest = FindViewById<Button> (Resource.Id.timertest);
			timerTest.Click += (object sender, EventArgs e) => {
				StartActivity(new Intent(this, typeof(StoveTop.TimerActivity)));
			};
			var seed = new Intent (this, typeof(SeedDatabase));
			StartActivity (seed);
		}
	}
}


